<?php
/**
 * Factory to create a definition handler of a given type.
 *
 * @author  Frank Kleine <frank.kleine@schlund.de>
 */
/**
 * Factory to create a definition handler of a given type.
 *
 * If the given type maps to an unknown definition handler it will create
 * an EmptyDefinitionHandler instead.
 *
 * @package     XJConf
 * @subpackage  definitions
 */
class DefinitionHandlerFactory
{
    /**
     * create a DefinitionHandler
     *
     * @param   string            $type       type of DefinitionHandler to create
     * @param   DefinitionParser  $defParser
     * @return  InvalidTagDefinitionException
     */
    public static function create($type, DefinitionParser $defParser)
    {
        $className = ucfirst($type) . 'DefinitionHandler';
        if (XJConfLoader::classFileExists('definitions.handler.' . $className) == false) {
            $className = 'EmptyDefinitionHandler';
        }
        
        XJConfLoader::load('definitions.handler.' . $className);
        
        $defHandler = new $className();
        $defHandler->init($defParser);
        return $defHandler;
    }
}
?>